package cn.tangsihai.hrm.client;

import cn.tangsihai.hrm.client.CourseSearchClient;
import cn.tangsihai.hrm.doc.CourseESDoc;
import cn.tangsihai.hrm.util.AjaxResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 降级工厂
 */
@Component
@Slf4j
public class CourseSearchClientFallbackFactory implements FallbackFactory<CourseSearchClient>{
    @Override
    public CourseSearchClient create(Throwable throwable) {
        return new CourseSearchClient() {
            // 将课程添加到ES中的降级方法
            @Override
            public AjaxResult addCourseToES(CourseESDoc esDoc) {
                log.error("添加异常：{}", throwable.getMessage());
                return AjaxResult.me().setMessage("添加异常");
            }

            // 将课程从ES中删除的降级方法
            @Override
            public AjaxResult deleteCourseFromES(Long id) {
                log.error("删除异常：{}", throwable.getMessage());
                return AjaxResult.me().setMessage("删除异常");
            }
        };
    }
}
